package com.techysky.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import com.techysky.entity.Note;
import com.techysky.repository.NoteRepository;
import com.techysky.service.NoteService;

@Service("noteService")
public class NoteServiceImpl implements NoteService {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	@Autowired
	private NoteRepository noteRepository;

	@Override
	public Note saveOrUpdate(Note note) {
		return this.noteRepository.save(note);
	}
	

	@Override
	public List<Note> findByContent(String content) {
		if("".equals(content))
		{
			return this.noteRepository.findAll();
		}
		else
		{
			return this.noteRepository.findByContentLike(StringUtils.isEmpty(content)?"":content);
		}
		
	}

	@Override
	public Object delete(String id) {
		 this.noteRepository.delete(id);
		 return "success";
	}

	@Override
	public List<Note> findByDmCode(String dmCode) {
		return this.noteRepository.findByDmCode(dmCode);
	}

}
